import {observable, action, computed, toJS} from 'mobx';
import {WeaSelect, WeaLocaleProvider} from 'ecCom';
import StringUtilsStore from './StringUtilsStore'

const getLabel = WeaLocaleProvider.getLabel;

let StringUtils = new StringUtilsStore()

export default class Store {

    @observable
    defaultTableDatas = [
        {
            id: 0,
            title: getLabel(6015, '我的报告'),
            selectedBigType: "1",
            reportDateRangeValue2: "",
            orderby: getLabel(508774, '报告状态') + "-" + getLabel(384984, "降序"),
            showCount: "1"
        },
        {
            id: 1,
            title: getLabel(508787, '所有报告'),
            selectedBigType: "2",
            reportDateRangeValue2: "",
            selectedReportStatus: "1",
            orderby: getLabel(508774, '报告状态') + "-" + getLabel(384984, "降序"),
            showCount: "1"
        },
        // {
        //     id: 2,
        //     title: getLabel(505884, '报告审批'),
        //     selectedBigType: "3",
        //     reportDateRangeValue2: "",
        //     orderby: getLabel(508774, '报告状态') + "-" + getLabel(384984, "降序"),
        //     showCount: "1"
        // }
    ]

    selectedTableDataId = ""

    @observable
    contentSettingDialogVisible = false

    @action
    changeContentSettingDialogVisible = (v) => {
        this.contentSettingDialogVisible = v
    }

    contentSettingDialogVisibleMethod = ""

    @action
    setDefaultContentSettingDialog = () => {
        this.tabTitle = ""
        this.selectedBigType = ""
        this.orderby = ""
        this.showCount = "0"
        this.reportDateRangeValue1 = new Date().getFullYear() + "",
        this.reportDateRangeValue2 = "",
        this.reportDateRangeValue3 = "",
        this.selectedReportStatus = ""
        this.selectedReportType = ""
        this.minScore = ""
        this.maxScore = ""
        this.reportPersonsStr = ""
        this.selectedSubDepOption = ""
        this.reportSubDepStr = ""
        this.selectedDepOption = ""
        this.reportDepStr = ""
    }

    @action
    setContentSettingDialog = (currTableData) => {
        // let currTableData = this.tableDatas[id]
        this.tabTitle = currTableData.title
        this.selectedBigType = currTableData.selectedBigType
        this.orderby = currTableData.orderby || ""
        this.showCount = currTableData.showCount
        this.reportDateRangeValue1 = currTableData.reportDateRangeValue1
        this.reportDateRangeValue2 = currTableData.reportDateRangeValue2
        this.reportDateRangeValue3 = currTableData.reportDateRangeValue3
        this.selectedReportStatus = currTableData.selectedReportStatus
        this.selectedReportType = currTableData.selectedReportType
        this.minScore = currTableData.minScore
        this.maxScore = currTableData.maxScore
        this.reportPersonsStr = currTableData.reportPersonsStr
        this.selectedSubDepOption = currTableData.selectedSubDepOption
        this.reportSubDepStr = currTableData.reportSubDepStr
        this.selectedDepOption = currTableData.selectedDepOption
        this.reportDepStr = currTableData.reportDepStr
    }

    @observable
    tabTitle = ""                 // tab页标题

    @action
    changeTabTitle = (tabTitle) => {
        this.tabTitle = tabTitle
    }

    @observable
    bigTypeOptions = [          // tab页所属大类别(我的报告，下属报告...)
        {
            key: "1",
            selected: false,
            showname: getLabel(6015, '我的报告')
        },{
            key: "2",
            selected: false,
            showname: getLabel(508787, '所有报告')
        },{
            key: "3",
            selected: false,
            showname: getLabel(505884, '报告审批')
        }
    ]

    @observable
    selectedBigType = "1"

    @computed
    get showReportStatusSetting () {
        return StringUtils.contains("1,2", this.selectedBigType)
    }

    @computed
    get showReportTypeSetting () {
        return StringUtils.contains("3", this.selectedBigType)
    }

    @computed
    get showReportPersonsSetting () {
        return StringUtils.contains("2,3", this.selectedBigType)
    }

    @computed
    get showReportSubDepSetting () {
        return StringUtils.contains("2,3", this.selectedBigType)
    }

    @computed
    get showReportDepSetting () {
        return StringUtils.contains("2,3", this.selectedBigType)
    }

    @action
    changeSelectedBigType = (bigType) => {
        this.bigType = bigType
    }

    @observable
    orderby = ""        // tab页内容列表数据排序方式中文说明

    @action
    changeOrderby = (orderby) => {
        this.orderby = orderby
    }

    @observable
    orderbyTransferDatas = [
        // {
        //     id: 1,
        //     orderType: "",
        //     name: "分数"
        // },
        {
            id: 2,
            orderType: "",
            name: getLabel(508774, '报告状态')
        }
        ,{
            id: 3,
            orderType: "",
            name: getLabel(508773, '报告人员')
        }
    ]

    @action
    changeOrderbyTransferDatas = (orderbyTransferDatas) => {
        this.orderbyTransferDatas = orderbyTransferDatas
    }

    @observable
    orderbyTransferSelectedKeys = []

    @action
    initOrderbyTransferDatas = () => {
        let selectedKeys = []
        this.orderbyTransferDatas.forEach((d, i) => {
            d.orderType = ""
        })
        this.orderby.split(",").forEach((d, i) => {
            this.orderbyTransferDatas.forEach((dd, ii) => {
                if (d.indexOf(dd.name) != -1) {
                    dd.orderType = d.split("-")[1]
                    selectedKeys.push(dd.id)
                }
            })
        })
        this.changeOrderbyTransferSelectedKeys(selectedKeys)
    }

    @action
    changeOrderbyTransferSelectedKeys = (orderbyTransferSelectedKeys) => {
        this.orderbyTransferSelectedKeys.forEach((d, i) => {
            this.orderbyTransferSelectedKeys[i] = ""
        })
        orderbyTransferSelectedKeys.forEach((d, i) => {
            this.orderbyTransferSelectedKeys[i] = d
        })
    }

    @observable
    orderbyTransferDialogVisible = false

    @action
    changeOrderbyTransferDialogVisible = (orderbyTransferDialogVisible) => {
        this.orderbyTransferDialogVisible = orderbyTransferDialogVisible
    }

    @observable
    showCount = "0"           // tab页是否显示数字

    @action
    changeShowCount = (showCount) => {
        this.showCount = showCount
    }

    @observable
    reportDateRangeValue1 = new Date().getFullYear() + ""

    @action
    changeReportDateRangeValue1 = (v) => {
        this.reportDateRangeValue1 = v
    }

    @observable
    reportDateRangeValue2 = ""

    @action
    changeReportDateRangeValue2 = (v) => {
        this.reportDateRangeValue2 = v
        if (v == "2-2") {
            this.changeReportDateRangeValue3(new Date().getMonth() + 1)
        } else {
            this.changeReportDateRangeValue3("")
        }
    }

    @observable
    reportDateRangeValue3 = ""

    @action
    changeReportDateRangeValue3 = (v) => {
        this.reportDateRangeValue3 = v
    }

    getReportDateRangeValues1Options () {
        let r = []
        let year = new Date().getFullYear()
        for (let i = 0; i < 10; i++) {
            let key = (year - i) + ""
            r.push({
                key,
                //selected: key == this.reportDateRangeValue1,
                showname: key
            })
        }
        return r
    }

    @observable
    reportDateRangeValues2Options = []

    @action
    changeReportDateRangeValues2Options = (value) => {
        this.reportDateRangeValues2Options = value
    }

    // @computed
    // get getReportDateRangeValues3Com () {
    //     if (this.reportDateRangeValue2 == "2-1") {
    //         return (
    //             <WeaSelect 
    //                 options = {[
    //                     {
    //                         key: "2-3-0",
    //                         showname: "全部"
    //                     },{
    //                         key: "2-3-1",
    //                         showname: "第1周"
    //                     },{
    //                         key: "2-3-2",
    //                         showname: "第2周"
    //                     },{
    //                         key: "2-3-3",
    //                         showname: "第3周"
    //                     },{
    //                         key: "2-3-4",
    //                         showname: "第4周"
    //                     }
    //                 ]}
    //                 value = {this.reportDateRangeValue3}
    //                 onChange = {(value) => {this.changeReportDateRangeValue3(value)}}
    //             />
    //         )
    //     } else if (this.reportDateRangeValue2 == "2-2") {
    //         return (
    //             <WeaSelect 
    //                 multiple = {true}
    //                 options = {
    //                     [
    //                         {
    //                             key: "2-4-1",
    //                             showname: "1月"
    //                         },{
    //                             key: "2-4-2",
    //                             showname: "2月"
    //                         },{
    //                             key: "2-4-3",
    //                             showname: "3月"
    //                         },{
    //                             key: "2-4-4",
    //                             showname: "4月"
    //                         },{
    //                             key: "2-4-5",
    //                             showname: "5月"
    //                         },{
    //                             key: "2-4-6",
    //                             showname: "6月"
    //                         },{
    //                             key: "2-4-7",
    //                             showname: "7月"
    //                         },{
    //                             key: "2-4-8",
    //                             showname: "8月"
    //                         },{
    //                             key: "2-4-9",
    //                             showname: "9月"
    //                         },{
    //                             key: "2-4-10",
    //                             showname: "10月"
    //                         },{
    //                             key: "2-4-11",
    //                             showname: "11月"
    //                         },{
    //                             key: "2-4-12",
    //                             showname: "12月"
    //                         }
    //                     ]
    //                 }
    //                 value = {this.reportDateRangeValue3}
    //                 onChange = {(value) => {this.changeReportDateRangeValue3(value)}}
    //             />
    //         )
    //     }
    // }

    @observable
    reportStatusOptions = [       // 报告状态
        {
            key: "0",
            selected: false,
            showname: getLabel(220, '草稿') 
        },{
            key: "1",
            selected: false,
            showname: getLabel(19134, '审批中') 
        },{
            key: "3",
            selected: false,
            showname: getLabel(23774, "已完成")
        }
        ,{
            key: "4",
            selected: false,
            showname: getLabel(382750, '已过期')
        }
        // ,{
        //     key: "2",
        //     selected: false,
        //     showname: getLabel(236, '退回')
        // }
        // ,{
        //     key: "-1",
        //     selected: false,
        //     showname: getLabel(25740, '其他')
        // }
    ]

    @observable
    selectedReportStatus = ""

    @action
    changeSelectedReportStatus = (v) => {
        this.selectedReportStatus = v
    }

    @observable
    reportTypeOptions = [       // 审批类型选项 
        {
            key: "1",
            selected: false,
            showname: getLabel(6106, '考核')
        },{
            key: "2",
            selected: false,
            showname: getLabel(30835, '审批')
        }
    ]

    @observable
    selectedReportType= ""

    @action
    changeSelectedReportType = (v) => {
        this.selectedReportType = v
    }

    @observable
    minScore = ""

    @action 
    changeMinScore = (score) => {
        this.minScore = score
    }

    @observable
    maxScore = ""

    @action
    changeMaxScore = (score) => {
        this.maxScore = score
    }

    @observable
    reportPersonsStr = ""

    @action
    changeReportPersonsStr = (ids, names) => {
        ids = ids ? ids : ""
        names = names ? names : ""

        let s = ""
        let idsArr = ids.split(",")
        let namesArr = names.split(",")
        idsArr.forEach((d, i) => {
            s += (d + "-" + namesArr[i] + ",")
        })
        this.reportPersonsStr = s.substring(0, s.length - 1)
    }

    @computed
    get reportPersonsObj () {
        let arr = []
        this.reportPersonsStr && this.reportPersonsStr.split(",").forEach((d, i) => {
            arr.push({
                id: d.split("-")[0],
                name: d.split("-")[1]
            })
        })
        return arr
    }

    @observable
    reportSubDepOptions = [
        {
            key: "1",
            selected: false,
            showname: getLabel(508780, '含子分部')
        },{
            key: "2",
            selected: false,
            showname: getLabel(18919, '仅本分部') 
        },{
            key: "3",
            selected: false,
            showname: getLabel(18920, '仅子分部')
        }
    ]

    @observable
    selectedSubDepOption = ""

    @action
    changeSelectedSubDepOption = (value) => {
        this.selectedSubDepOption = value
    }

    @observable
    reportSubDepStr = ""

    @action
    changeReportSubDepStr = (ids, names) => {
        ids = ids ? ids : ""
        names = names ? names : ""

        let s = ""
        let idsArr = ids.split(",")
        let namesArr = names.split(",")
        idsArr.forEach((d, i) => {
            s += (d + "-" + namesArr[i] + ",")
        })
        this.reportSubDepStr = s.substring(0, s.length - 1)
    }

    @computed
    get reportSubDepObj () {
        let arr = []
        this.reportSubDepStr && this.reportSubDepStr.split(",").forEach((d, i) => {
            arr.push({
                id: d.split("-")[0],
                name: d.split("-")[1]
            })
        })
        return arr
    }

    @observable
    reportDepOptions = [
        {
            key: "1",
            selected: false,
            showname: getLabel(508784, '含子部门') 
        },{
            key: "2",
            selected: false,
            showname: getLabel(18916, '仅本部门') 
        },{
            key: "3",
            selected: false,
            showname: getLabel(18917, '仅子部门')
        }
    ]

    @observable
    selectedDepOption = ""

    @action
    changeSelectedDepOption = (value) => {
        this.selectedDepOption = value
    }

    @observable
    reportDepStr = ""

    @action
    changeReportDepStr = (ids, names) => {
        ids = ids ? ids : ""
        names = names ? names : ""

        let s = ""
        let idsArr = ids.split(",")
        let namesArr = names.split(",")
        idsArr.forEach((d, i) => {
            s += (d + "-" + namesArr[i] + ",")
        })
        this.reportDepStr = s.substring(0, s.length - 1)
    }

    @computed
    get reportDepObj () {
        let arr = []
        this.reportDepStr && this.reportDepStr.split(",").forEach((d, i) => {
            arr.push({
                id: d.split("-")[0],
                name: d.split("-")[1]
            })
        })
        return arr
    }
}